package com.uchengwang.ui.cm_ui.ucity.ui;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.http.config.BaseConfig;
import com.uchengwang.functions.http.listener.OnHttpResultSingleListener;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.UChengApplication;
import com.uchengwang.ui.base_ui.ui.BaseWithTitleActivity;
import com.uchengwang.ui.utils.QRCodeUtils;

/**
 * Created by U城网 on 2018/1/31.
 * 二维码显示界面
 */

public class QRCodeShowActivity extends BaseWithTitleActivity{
    private TextView name;
    private ImageView imageQr, imageHead;
    private int type;//1用户二维码  2会场二维码
    private long id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_qr_code_show);
        type = getIntent().getIntExtra(BaseConfig.TYPE, 0);
        id = getIntent().getLongExtra(BaseConfig.ID, 0);
        setTitle("二维码");
        initView();
    }
    private void initView(){
        name = (TextView) findViewById(R.id.qrShow_name);
        imageQr = (ImageView) findViewById(R.id.qrShow_imageQr);
        imageHead = (ImageView) findViewById(R.id.qrShow_imageHead);


        initData();
    }

    private void initData(){
        switch (type){
            case 1:
                name.setText(UChengApplication.nickName);
                QRCodeUtils.getUtils().createQRCode(this, BaseConfig.BaseWebURL + "/user/"+ id, new OnHttpResultSingleListener<Bitmap>() {
                    @Override
                    public void onResult(int status, String msg, final Bitmap bitmap) {
                        QRCodeShowActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                imageQr.setImageBitmap(bitmap);
                                ImageManager.getInstance().loadImage(QRCodeShowActivity.this, imageHead, UChengApplication.userAvatar, ImageManager.ImageType.ROUND);

                            }
                        });
                    }
                });
                break;
            case 2:

                break;
        }


    }
}
